

'use strict';

var express = require("express");

var path = require("path");

var bodyParser = require('body-parser');

var proxy = require('http-proxy-middleware');

var options = {
  target: 'http://localhost:8888', // target host
  changeOrigin: true, // needed for virtual hosted sites
  ws: true, // proxy websockets
  pathRewrite: {
    '^/api': '/' // 路径重写
    
  },
  router: {
    // when request.headers.host == 'dev.localhost:3000',
    // override target 'http://www.example.org' to 'http://localhost:8000'
    //'localhost:3000': 'http://localhost:8888'
  }
}

var exampleProxy = proxy(options)

var app = express();

//对api开头的路径进行代理转发
app.use('/api', exampleProxy);

app.set('views', __dirname + '/../');

app.use(express["static"](path.join(__dirname, '../')));

app.use(bodyParser.json());

require('./routes')(app);



app.listen(8080);

console.log('Server is listening on port 8080');
